package com.project.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.server.mapper.DishMapper;
import com.project.server.model.Dish;
import com.project.server.service.DishService;
import com.project.server.vo.DishVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
@RequiredArgsConstructor
public class DishServiceImpl implements DishService {

    private final DishMapper dishMapper;

    @Override
    public Page<DishVO> page(Integer pageNum, Integer pageSize, String name, Long categoryId, Long restaurantId, Integer status) {
        Page<Dish> page = new Page<>(pageNum, pageSize);
        return dishMapper.getDishPage(page, name, categoryId, restaurantId, status);
    }

    @Override
    public Dish getById(Long id) {
        return dishMapper.selectById(id);
    }

    @Override
    public void save(Dish dish) {
        dish.setStatus(1); // 默认上架
        dish.setSales(0); // 初始销量为0
        dishMapper.insert(dish);
    }

    @Override
    public void update(Dish dish) {
        dishMapper.updateById(dish);
    }

    @Override
    public void removeById(Long id) {
        dishMapper.deleteById(id);
    }

    @Override
    public void updateStatus(Long id, Integer status) {
        Dish dish = new Dish();
        dish.setId(id);
        dish.setStatus(status);
        dishMapper.updateById(dish);
    }

    @Override
    public List<Dish> getHotDishes(Long restaurantId, Long pageSize) {
        return dishMapper.getHotDishes(pageSize);
    }
}
